package com.smart.village.big.screen.controller.change;

import com.smart.village.big.screen.domain.AjaxResult;
import com.smart.village.big.screen.service.ChangeAgricultureService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.logging.Logger;

import static com.smart.village.big.screen.domain.AjaxResult.error;

/**
 * 新修改-数智农业数据接口
 */
@Tag(name = "新修改-数智农业数据接口")
@RestController
@RequestMapping("/change/agriculture")
public class ChangeAgricultureController {
    @Autowired
    private ChangeAgricultureService changeAgricultureService;
    private Logger logger = Logger.getLogger(ChangeAgricultureController.class.getName());
    /**
     * 数智农业 基础数据 产业结构
     *
     * @return
     */
    @Operation(summary = "数智农业 基础数据 产业结构 ")
    @Parameters({
            @Parameter(name = "year", description = "年份 必传默认当前年"),
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 必传")
    })
    @GetMapping("/getIndustrialStructureStatics")
    @ResponseBody
    public AjaxResult getIndustrialStructureStatics(
            @RequestParam String year,
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber
    ) {
        try {
            return AjaxResult.success(changeAgricultureService.getIndustrialStructureStatics(year, townNumber, villageNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }
    /**
     * 数智农业 基础数据 重点农业项目
     *
     * @return
     */
    @Operation(summary = "数智农业 基础数据 重点农业项目")
    @Parameters({
            @Parameter(name = "year", description = "年份 必传默认当前年"),
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 必传"),
            @Parameter(name = "pageNum", description = "当前页数 非必传默认1"),
            @Parameter(name = "pageSize", description = "每页条数 非必传默认10")
    })
    @GetMapping("/getImportantAgricultureProjectList")
    @ResponseBody
    public AjaxResult getImportantAgricultureProjectList(
            @RequestParam String year,
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        try {
            return AjaxResult.success(changeAgricultureService.getImportantAgricultureProjectList(year, townNumber, villageNumber,pageNum,pageSize));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 数智农业 补贴信息
     *
     * @return
     */
    @Operation(summary = "数智农业 补贴信息 ")
    @Parameters({
            @Parameter(name = "year", description = "年份 必传默认当前年"),
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 必传")
    })
    @GetMapping("/getSubsidyInformation")
    @ResponseBody
    public AjaxResult getSubsidyInformation(
            @RequestParam String year,
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber
    ) {
        try {
            return AjaxResult.success(changeAgricultureService.getSubsidyInformation(year, townNumber, villageNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 数智农业 基础数据 视频监控
     *
     * @return
     */
    @Operation(summary = "数智农业 基础数据 视频监控 ")
    @GetMapping("/getMonitorDeviceList")
    @ResponseBody
    public AjaxResult getMonitorDeviceList(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        try {
            return AjaxResult.success(changeAgricultureService.getMonitorDeviceList(townNumber, villageNumber, pageNum, pageSize));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }


    /**
     * 数智农业 基础数据 三资台账
     *
     * @return
     */
    @Operation(summary = "数智农业 基础数据 三资台账 ")
    @GetMapping("/getThreeResourceInformationList")
    @ResponseBody
    @Parameters({
            @Parameter(name = "type", description = "类型 必传 【资产 资源 资金】"),
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必传"),
            @Parameter(name = "pageNum", description = "当前页数 非必传默认1"),
            @Parameter(name = "pageSize", description = "每页条数 非必传默认10")
    })
    public AjaxResult getThreeResourceInformationList(
            @RequestParam String type,
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        try {
            return AjaxResult.success(changeAgricultureService.getThreeResourceInformationList(type,townNumber, villageNumber, pageNum, pageSize));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 数智农业 根据 村镇 获取自然资源坐标列表 渲染地图
     *
     * @return
     */
    @Operation(summary = "数智农业 根据 村镇 获取自然资源坐标列表 渲染地图")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 必传"),
            @Parameter(name = "type", description = "类型 【耕地分布(确权数据)、补贴区域、畜牧养殖、林下种植、特色种植、我在北极有块田】"),
    })
    @GetMapping("/getNaturalResourcesCoords")
    @ResponseBody
    public AjaxResult getNaturalResourcesCoords(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false) String type
    ) {
        try {
            return AjaxResult.success(changeAgricultureService.getNaturalResourcesCoords(townNumber,
                    villageNumber,
                    type
                   ));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 数智农业 我在北极有块田 视频监控
     *
     * @return
     */
    @Operation(summary = "数智农业 我在北极有块田 视频监控 ")
    @GetMapping("/getBeiJiMonitorDeviceList")
    @ResponseBody
    public AjaxResult getBeiJiMonitorDeviceList(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        try {
            return AjaxResult.success(changeAgricultureService.getBeiJiMonitorDeviceList(townNumber, villageNumber, pageNum, pageSize));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }
    /**
     * 数智农业 我在北极有块田 地块种植概览
     *
     * @return
     */
    @Operation(summary = "数智农业 我在北极有块田 地块种植概览 ")
    @GetMapping("/getBeiJiOverview")
    @ResponseBody
    public AjaxResult getBeiJiOverview(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber
    ) {
        try {
            return AjaxResult.success(changeAgricultureService.getBeiJiOverview(townNumber, villageNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }
    /**
     * 数智农业 我在北极有块田 地块种植 - 点击地图
     *
     * @return
     */
    @Operation(summary = "数智农业 我在北极有块田 地块种植 - 点击地图")
    @GetMapping("/getBeiJiOverviewDetail")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 必传"),
            @Parameter(name = "type", description = "类型 【总地块数 有块田数量 可认领作物和土地 种植者数量】"),
            @Parameter(name = "cropCategorySerialNumber", description = "当类型是有块田数量得时候，作为筛选条件，作物分类编码 非必传"),
            @Parameter(name = "ifContract", description = "当类型是 可认领作物和土地得时候，作为筛选条件，是否认养 非必传 【已认养 未认养】")
    })
    @ResponseBody
    public AjaxResult getBeiJiOverviewDetail(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false) String type,
            @RequestParam(required = false) String cropCategorySerialNumber,
            @RequestParam(required = false) String ifContract
    ) {
        try {
            return AjaxResult.success(changeAgricultureService.getBeiJiOverviewDetail(townNumber, villageNumber, type,cropCategorySerialNumber,ifContract));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }
    /**
     * 数智农业 我在北极有块田 地块种植  作物类型 图例
     *
     * @return
     */
    @Operation(summary = "数智农业 我在北极有块田 地块种植  作物类型 图例 ")
    @GetMapping("/getCropCategory")
    @ResponseBody
    public AjaxResult getCropCategory(
    ) {
        try {
            return AjaxResult.success(changeAgricultureService.getCropCategory());
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }
    /**
     * 数智农业 我在北极有块田 有块田地块列表
     *
     * @return
     */
    @Operation(summary = "数智农业 我在北极有块田 有块田地块列表 ")
    @GetMapping("/getBeiJiHaveAFiledList")
    @ResponseBody
    public AjaxResult getBeiJiHaveAFiledList(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        try {
            return AjaxResult.success(changeAgricultureService.getBeiJiHaveAFiledList(townNumber, villageNumber, pageNum, pageSize));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 数智农业 我在北极有块田 有块田地块 详情
     *
     * @return
     */
    @Operation(summary = "数智农业 我在北极有块田 有块田地块 详情 ")
    @GetMapping("/getBeiJiHaveAFiledDetail")
    @ResponseBody
    public AjaxResult getBeiJiHaveAFiledDetail(
            @RequestParam String naturalResourceSerialNumber
    ) {
        try {
            return AjaxResult.success(changeAgricultureService.getBeiJiHaveAFiledDetail(naturalResourceSerialNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }
    /**
     * 数智农业 我在北极有块田 作物种植面积分布
     *
     * @return
     */
    @Operation(summary = "数智农业 我在北极有块田 作物种植面积分布 ")
    @GetMapping("/getCropAreaDistribution")
    @ResponseBody
    public AjaxResult getCropAreaDistribution(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false,defaultValue = "5") String year
    ) {
        try {
            return AjaxResult.success(changeAgricultureService.getCropAreaDistribution(townNumber, villageNumber,year));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 数智农业 我在北极有块田 作物类型占比
     *
     * @return
     */
    @Operation(summary = "数智农业 我在北极有块田 作物类型占比 ")
    @GetMapping("/getCropTypeDistribution")
    @ResponseBody
    public AjaxResult getCropTypeDistribution(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber
    ) {
        try {
            return AjaxResult.success(changeAgricultureService.getCropTypeDistribution(townNumber, villageNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 数智农业 我在北极有块田 实时设备 列表
     *
     * @return
     */
    @Operation(summary = "数智农业 我在北极有块田 实时设备 列表 ")
    @GetMapping("/getMonitorDeviceRealTimeList")
    @ResponseBody
    public AjaxResult getMonitorDeviceRealTimeList(
            @RequestParam String natureResourceSerialNumber

    ) {
        try {
            return AjaxResult.success(changeAgricultureService.getMonitorDeviceRealTimeList(natureResourceSerialNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }


}
